/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.CosBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.SoapProtocol;
/*    */ import com.zimbra.common.util.SystemUtil;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.Entry;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.mailbox.RetentionPolicyManager;
/*    */ import com.zimbra.soap.JaxbUtil;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import com.zimbra.soap.admin.message.ModifySystemRetentionPolicyRequest;
/*    */ import com.zimbra.soap.admin.message.ModifySystemRetentionPolicyResponse;
/*    */ import com.zimbra.soap.admin.type.CosSelector;
/*    */ import com.zimbra.soap.admin.type.CosSelector.CosBy;
/*    */ import com.zimbra.soap.mail.type.Policy;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ModifySystemRetentionPolicy
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 44 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*    */     
/* 46 */     ModifySystemRetentionPolicyRequest req = (ModifySystemRetentionPolicyRequest)JaxbUtil.elementToJaxb(request);
/* 47 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 49 */     Entry entry = prov.getConfig();
/*    */     
/* 51 */     CosSelector cosSelector = req.getCos();
/* 52 */     if (cosSelector != null) {
/* 53 */       entry = prov.get(Key.CosBy.fromString(cosSelector.getBy().name()), cosSelector.getKey());
/* 54 */       if (entry == null) {
/* 55 */         throw AccountServiceException.NO_SUCH_COS(cosSelector.getKey());
/*    */       }
/*    */     }
/* 58 */     CreateSystemRetentionPolicy.checkSetRight(entry, zsc, context, this);
/*    */     
/*    */ 
/* 61 */     Policy p = req.getPolicy();
/* 62 */     if (p == null) {
/* 63 */       throw ServiceException.INVALID_REQUEST("policy not specified", null);
/*    */     }
/* 65 */     if (p.getId() == null) {
/* 66 */       throw ServiceException.INVALID_REQUEST("id not specified for policy", null);
/*    */     }
/*    */     
/* 69 */     RetentionPolicyManager mgr = RetentionPolicyManager.getInstance();
/* 70 */     String id = p.getId();
/* 71 */     Policy current = mgr.getPolicyById(entry, id);
/* 72 */     if (current == null) {
/* 73 */       throw ServiceException.INVALID_REQUEST("Could not find system retention policy with id " + id, null);
/*    */     }
/* 75 */     String name = (String)SystemUtil.coalesce(new String[] { p.getName(), current.getName() });
/* 76 */     String lifetime = (String)SystemUtil.coalesce(new String[] { p.getLifetime(), current.getLifetime() });
/* 77 */     Policy latest = mgr.modifySystemPolicy(entry, id, name, lifetime);
/* 78 */     ModifySystemRetentionPolicyResponse res = new ModifySystemRetentionPolicyResponse(latest);
/* 79 */     return JaxbUtil.jaxbToElement(res, zsc.getResponseProtocol().getFactory());
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 84 */     notes.add("Need set attr right on attribute zimbraMailPurgeSystemPolicy");
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/ModifySystemRetentionPolicy.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */